﻿var job;
$(function () {
    placeholder();

    $("#areaId").ligerComboBox({
        width: 70,
        selectBoxWidth: 100,
        cancelable: false,
        url: "/Personnel/PersonnelFileList/GetDepartmentList?ram" + Math.random(),
        parms: { isAll: 1 },
        valueField: "value",
        textField: "text",
        valueFieldID: 'hdnAreaId',
        value: -1,
        onSuccess: function (data) { }
    });

    $("#sex").ligerComboBox({
        cancelable: false,
        width: 60,
        valueFieldID: 'hdnSex'
    });

    $("#hireType").ligerComboBox({
        cancelable: false,
        width: 80,
        selectBoxWidth: 100,
        valueFieldID: 'hdnHireType'
    });

    $("#inServiceStatus").ligerComboBox({
        width: 80,
        cancelable: false,
        valueFieldID: 'hdnInServiceStatus',
        value: -1
    });

    $("#nursingAge").ligerComboBox({
        cancelable: false,
        width: 100,
        valueFieldID: 'hdnNursingAge'
    });

    bindStatus();

    $('#btnSearch').click(function () {
        search();
    });

    search();
});

function bindStatus() {
    var JsonObj = [];

    $.ajax({
        url: "/Personnel/PersonnelReview/GetReviewProcess?ram" + Math.random(),
        type: "post",
        async: false,
        success: function (r) {
            job = $.parseJSON(r);
            JsonObj.push({ text: "全部", value: -1 });
            if (job.IncludeStatus == "" || job.IncludeStatus == null) return;
            var includeStatus = job.IncludeStatus.split('|');
            var statusAlias = job.StatusAlias.split('|');
            for (var ii = 0; ii < includeStatus.length; ii++) {
                JsonObj.push({ text: statusAlias[ii], value: includeStatus[ii] });
            }
        }
    });

    $("#status").ligerComboBox({
        width: 60,
        selectBoxWidth: 100,
        cancelable: false,
        valueField: "value",
        textField: "text",
        valueFieldID: 'hdnStatus',
        data: JsonObj,
        value: -1
    });
}

//加载列表
function initTable(queryData, pageNumber) {
    $("#maingrid").ligerGrid({
        height: '100%',
        url: '/Personnel/PersonnelFileList/Search?ram=' + Math.random(),
        parms: queryData,
        page: pageNumber,
        pageSize: 30,
        rownumbers: true,
        heightDiff: -5,
        columns: [
        { display: '工号', name: 'UserId', width: 100 },
        { display: '姓名', name: 'Name', width: 100 },
        { display: '性别', name: 'Sex', width: 100 },
        { display: '民族', name: 'Nation', width: 100 },
        {
            display: '政治面貌', name: 'PoliticalStatus', width: 100, render: function (row) {
                return row.PoliticalStatus == -1 ? "" : row.PoliticalStatus;
            }
        },
        { display: '联系电话', name: 'Telephone', width: 100 },
        { display: '身份证号', name: 'IdCardNo', width: 100 },
        {
            display: '学历', name: 'Education', width: 100, render: function (row) {
                return row.Education == -1 ? "" : row.Education;
            }
        },
        { display: '职称', name: 'JobCode', width: 100 },
        {
            display: '职称', name: 'PositionCode', width: 100, render: function (row) {
                return row.PositionCode == -1 ? "" : row.PositionCode;
            }
        },
        {
            display: '能级', name: 'EnergyLevel', width: 100, render: function (row) {
                return row.EnergyLevel == -1 ? "" : row.EnergyLevel;
            }
        },
        {
            display: '聘用类型', name: 'HireType', width: 100, render: function (row) {
                var value = "";
                if (row.HireType == 0) {
                    value = "在编";
                }
                else if (row.HireType == 1) {
                    value = "临聘";
                }
                else if (row.HireType == 2) {
                    value = "返聘";
                }
                else if (row.HireType == 3) {
                    value = "无固定期限合同";
                }
                return value;
            }
        },
        { display: '出生日期', name: 'Birthday', width: 100 },
        { display: '本院到岗日期', name: 'InDate', width: 100 },
        { display: '身高', name: 'Height', width: 100 },
        {
            display: '鞋码', name: 'ShoeSize', width: 100, render: function (row) {
                return row.ShoeSize == -1 ? "" : row.ShoeSize;
            }
        },
        { display: '籍贯', name: 'Birthplace', width: 100 },
        { display: '家庭住址', name: 'Address', width: 100 },
        { display: '护士执业证书编号', name: 'HszyzsCode', width: 120 },
        { display: '专科护士证书名称', name: 'ZkhszsTitle', width: 120 },
        {
            display: '人员状态', name: 'InServiceStatus', width: 100, render: function (row) {
                var value = "";
                if (row.InServiceStatus == 0) {
                    value = "在岗";
                }
                else if (row.InServiceStatus == 1) {
                    value = "离职";
                }
                else if (row.InServiceStatus == 2) {
                    value = "休假";
                }
                else if (row.InServiceStatus == 3) {
                    value = "进修";
                }
                return value;
            }
        },
        { display: '提交时间', name: 'CommitTime', width: 100 },
        {
            display: '审核状态', name: '', width: 100, render: function (row) {
                if (job.IncludeStatus == null) return;
                var html = '';
                var includeStatus = job.IncludeStatus.split('|');
                var statusAlias = job.StatusAlias.split('|');
                for (var i = 0; i < includeStatus.length; i++) {
                    if (includeStatus[i] == row.Status) {
                        html = statusAlias[i];
                        break;
                    }
                }
                return html;
            }
        }
        ]
    });
    GridNoData($("#maingrid"));
}

//搜索
function search(pageNumber) {
    var startHeight = $("#txtStartHeight").val();
    var endHeight = $("#txtEndHeight").val();
    var startShoeSize = $("#txtStartShoeSize").val();
    var endShoeSize = $("#txtEndShoeSize").val();
    var startAge = $("#txtStartAge").val();
    var endAge = $("#txtEndAge").val();
    if (startHeight > endHeight) {
        $("#txtStartHeight").val(endHeight);
        $("#txtEndHeight").val(startHeight);
    }
    if (startShoeSize > endShoeSize) {
        $("#txtStartShoeSize").val(endShoeSize);
        $("#txtEndShoeSize").val(startShoeSize);
    }
    if (startAge > endAge) {
        $("#txtStartAge").val(endAge);
        $("#txtEndAge").val(startAge);
    }

    queryData = {
        areaId: $("#hdnAreaId").val(),
        inServiceStatus: $("#hdnInServiceStatus").val(),
        hireType: $("#hdnHireType").val(),
        sex: $("#hdnSex").val(),
        status: $("#hdnStatus").val(),
        name: $("#txtName").val() == $("#txtName").attr("datavalue") ? "" : $("#txtName").val(),
        zkhszsTitle: $("#txtZkhszsTitle").val() == $("#txtZkhszsTitle").attr("datavalue") ? "" : $("#txtZkhszsTitle").val(),
        startHeight: $("#txtStartHeight").val(),
        endHeight: $("#txtEndHeight").val(),
        startShoeSize: $("#txtStartShoeSize").val(),
        endShoeSize: $("#txtEndShoeSize").val(),
        startAge: $("#txtStartAge").val(),
        endAge: $("#txtEndAge").val(),
        nursingAge: $("#hdnNursingAge").val()
    }
    initTable(queryData, pageNumber);
}